#set(seoTitle="发布文章")
#@layout()
#define main()
<!-- 内容区域 -->
<div class="aw-container-wrap">
    <div class="container aw-publish aw-publish-article">
        <div class="row">
            <div class="aw-content-wrap clearfix">
                <div class="col-sm-12 col-md-12 aw-main-content">
                    <!-- tab 切换 -->
                    <ul class="nav nav-tabs aw-nav-tabs active">
                        <h2><i class="icon icon-ask"></i>发起文章</h2>
                    </ul>
                    <!-- end tab 切换 -->
                    <form id="myArticleForm" action="/my/article/save" method="post" name="write_post">
                        <div class="aw-mod aw-mod-publish">
                            <div class="mod-body">
                                <!-- 文章标题 -->
                                <div class="aw-publish-title">
                                    <div class="input-group" style="margin-top: 10px">
                                        <span class="input-group-addon" id="basic-addon3">文章标题</span>
                                        <input type="text" name="article.title" value="" class="form-control" placeholder="请输入标题">
                                        <span class="input-group-addon" id="basic-addon4">分类</span>
                                        <select name="article.type_id" class="form-control" id="article.type_id">
                                            #for(comments : commentsList)
                                            <option value="#(comments.tid)">#(comments.name)</option>
                                            #end
                                        </select>
                                    </div>
                                </div>
                                <h3>是否使用积分下载
                                    <span style="margin-left: 5px">
                                    <label class="radio-inline">
                                        <input type="radio" name="article.is_pay" value="0" checked>否
                                    </label>
                                    <label class="radio-inline">
                                        <input type="radio" name="article.is_pay" value="1">是
                                    </label>
                                    </span>
                                </h3>

                                <div class="aw-publish-title">
                                    <div class="input-group" style="margin-top: 10px">
                                        <span class="input-group-addon" id="basic-addon5">下载链接</span>
                                        <input type="text" name="article.download" value="" class="form-control" placeholder="请输入下载链接"><br/>
                                    </div>
                                    <div class="input-group" style="margin-top: 10px">
                                        <span class="input-group-addon" id="basic-addon6">下载密码</span>
                                        <input type="text" name="article.password" value="" class="form-control" placeholder="请输入下载密码">
                                        <span class="input-group-addon" id="basic-addon7">使用积分</span>
                                        <select name="article.points" class="form-control" id="article.points">
                                            <option value="1">1个积分</option>
                                            <option value="2">2个积分</option>
                                            <option value="3">3个积分</option>
                                            <option value="4">4个积分</option>
                                            <option value="5">5个积分</option>
                                            <option value="6">6个积分</option>
                                            <option value="7">7个积分</option>
                                            <option value="8">8个积分</option>
                                            <option value="9">9个积分</option>
                                            <option value="10">10个积分</option>
                                        </select>
                                    </div>
                                </div>
                                <!-- end 文章标题 -->
                                <h3>文章内容:</h3>
                                <div class="content-box" style="line-height: 20px;border: 1px solid #d1d1d1;">
                                    <!--<script id="container" name="article.content" style="line-height: 20px;"  type="text/plain" ></script>-->
                                    <textarea id="editor1" name="article.content"></textarea>
                                </div>
                            </div>
                            <div class="mod-footer clearfix">
                                <a href="/detail/1" target="_blank">[积分规则]</a>
                                <span class="aw-anonymity"></span>
                                <input class="btn btn-large btn-success btn-publish-submit" type="submit"
                                       value="确认&nbsp;发起"/>
                            </div>
                        </div>
                    </form>

                </div>
            </div>
        </div>
    </div>
</div>
<!-- 内容区域end -->
#end

#define js()
<script type="text/javascript" src="/static/lib/jquery_form/jquery.form.min.js"></script>
<script src="/static/lib/ckeditor/ckeditor.js"></script>
<script>
    $(function() {
        // 初始化 ckeditor
        CKEDITOR.replace('editor1', {height: '350px'});
        // 设置第一个 input 为输入焦点
        $("input:first").focus();
        // 使用 jquery form 插件，接管表单提交事件，并将表单提交自动转化成 ajax 提交
        $("#myArticleForm").ajaxForm({
            dataType: 'json', type: 'POST',
            beforeSerialize: function($form, options) {
                // 将 ckeditor 中的数据同步到 textarea，否则数据无法提交到服务端
                for (instance in CKEDITOR.instances) {
                    CKEDITOR.instances[instance].updateElement();
                }
                kit.loading({msg: '正在保存, 请稍候 .....'});
            },
            success: function(ret) {
                kit.closeLoading();
                if (ret.state == "ok") {
                    kit.go('/my/article/list');
                }else{
                    showErrorMsg(ret.msg);
                }
            }
            , error: function (ret) {
                kit.msg(ret.msg);
            }
            , complete: function (ret) {
            }       // 无论是 success 还是 error，最终都会被回调
        });

    });
</script>
#end